/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CancelaIngressoSentado.java
 *
 * Created on 28/06/2012, 03:25:56
 */
package View;

import Controller.Controller;
import Model.Cargo;
import Model.Evento;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Rodrigo
 */
public class CancelaIngressoSentado extends javax.swing.JFrame {

    Controller controller;
    Evento evento;
    List<JPanel> cadeiras;

    /** Creates new form CancelaIngressoSentado */
    public CancelaIngressoSentado(Evento evento) {
        this.evento = evento;
        cadeiras = new ArrayList<JPanel>();
        controller = Controller.getInstance();
        initComponents();
        txtIndisponivel.setVisible(false);
        txtDisponivel.setVisible(false);
    }

    public void verificaDisponibilidade() {
        if (!controller.verificaDisponibilidadeCadeira(evento, numero.getSelectedItem().toString(), fileira.getSelectedItem().toString())) {
            txtDisponivel.setVisible(true);
            txtIndisponivel.setVisible(false);
        } else {
            txtDisponivel.setVisible(false);
            txtIndisponivel.setVisible(true);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtDisponivel = new javax.swing.JLabel();
        btnConfirmar = new javax.swing.JButton();
        txtIndisponivel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        labelFileira = new javax.swing.JLabel();
        fileira = new javax.swing.JComboBox();
        numero = new javax.swing.JComboBox();
        labelNumero = new javax.swing.JLabel();
        voltarButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txtDisponivel.setFont(new java.awt.Font("Tahoma", 1, 12));
        txtDisponivel.setForeground(new java.awt.Color(0, 204, 0));
        txtDisponivel.setText("Cadeira Ocupada");

        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });

        txtIndisponivel.setFont(new java.awt.Font("Tahoma", 1, 12));
        txtIndisponivel.setForeground(new java.awt.Color(204, 0, 0));
        txtIndisponivel.setText("Cadeira Desocupada");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("Cancelar Ingresso");

        labelFileira.setText("Fileira");

        fileira.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }));
        fileira.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileiraActionPerformed(evt);
            }
        });

        numero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numeroActionPerformed(evt);
            }
        });

        labelNumero.setText("Numero");

        voltarButton.setText("Voltar");
        voltarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(voltarButton)
                .addContainerGap(557, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(98, 98, 98)
                    .addComponent(labelFileira)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(13, 13, 13)
                            .addComponent(jLabel1))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(fileira, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(45, 45, 45)
                            .addComponent(labelNumero)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(33, 33, 33)
                            .addComponent(btnConfirmar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtDisponivel)
                                .addComponent(txtIndisponivel))))
                    .addContainerGap(98, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(415, Short.MAX_VALUE)
                .addComponent(voltarButton)
                .addGap(41, 41, 41))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jLabel1)
                    .addGap(346, 346, 346)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDisponivel)
                            .addComponent(txtIndisponivel))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fileira, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelFileira)
                            .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelNumero)
                            .addComponent(btnConfirmar)))
                    .addContainerGap(41, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed

        // TODO add your handling code here:         if (!controller.vendeIngressoCadeira(fileira.getSelectedItem().toString(), numero.getSelectedItem().toString(), evento)) {             JOptionPane.showMessageDialog(null, "Cadeira ocupada! Por favor, escolha outra.", "Erro", JOptionPane.ERROR_MESSAGE);         } else {             JOptionPane.showMessageDialog(null, "Compra efetuada com sucesso!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);         }     }//GEN-LAST:event_btnConfirmarActionPerformed

        if (!controller.cancelaIngressoCadeira(fileira.getSelectedItem().toString(), numero.getSelectedItem().toString(), evento)) {
            JOptionPane.showMessageDialog(null, "Cadeira ocupada! Por favor, escolha outra.", "Erro", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "Ingresso Cancelado!", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
        }
    }

        private void fileiraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileiraActionPerformed
            // TODO add your handling code here:
            verificaDisponibilidade();
    }//GEN-LAST:event_fileiraActionPerformed

    private void numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numeroActionPerformed

        // TODO add your handling code here:         verificaDisponibilidade();     }//GEN-LAST:event_numeroActionPerformed
        verificaDisponibilidade();
    }

        private void voltarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarButtonActionPerformed
            if (controller.getCargo() == Cargo.GERENTE) {
                VerEventoGerente veg = new VerEventoGerente(evento);
                veg.setVisible(true);
                this.setVisible(false);
            } else {
                VerEventoBilheteria veb = new VerEventoBilheteria(evento);
                veb.setVisible(true);
                this.setVisible(false);
            }
    }//GEN-LAST:event_voltarButtonActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CancelaIngressoSentado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CancelaIngressoSentado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CancelaIngressoSentado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CancelaIngressoSentado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CancelaIngressoSentado(new Evento()).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JComboBox fileira;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel labelFileira;
    private javax.swing.JLabel labelNumero;
    private javax.swing.JComboBox numero;
    private javax.swing.JLabel txtDisponivel;
    private javax.swing.JLabel txtIndisponivel;
    private javax.swing.JButton voltarButton;
    // End of variables declaration//GEN-END:variables
}
